<?php
use \tpfcore\Core;
use \tpfcore\helpers\StringHelper;
?>
<!doctype html>
<html>
    
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>TPF-公众号管理插件</title>
    <link rel="stylesheet" type="text/css" href="{$static_path}/css/common.css" />
    <link rel="stylesheet" type="text/css" href="{$static_path}/css/main.css" />
    <link rel="stylesheet" type="text/css" href="{$static_path}/css/core.css" />
    <link rel="stylesheet" type="text/css" href="{$static_path}/css/reveal.css" />
    <script src="{$static_path}/js/jquery-1.12.2.min.js" language="javascript"></script>
    <script src="{$static_path}/js/jquery.reveal.js" language="javascript"></script>
    <script src="{$static_path}/js/core.js" language="javascript"></script>
    <script type="text/javascript" src="{$static_path}/js/modernizr.min.js"></script>
	<style type="text/css">
        .btn-post{clear:both; margin:10px 10px; height:30px;}
        .a-btn-post{background:#44b549 ; color:#FFFFFF; font-size: 14px;font-weight: 400; display:block; width:125px; height:30px; line-height:30px; text-align:center;border-radius: 4px; float:left; margin-right:20px }
        .a-btn-post:hover{color:#FFFFFF; background:#339933}

        .ke-upload-area .ke-button-common,.uploadButton,.ke-upload-file {
            background:#44b549;height:30px;line-height:30px;text-align:center;color:#fff;display:block;float:left;z-index:1;font-size:13px;}
        .uploadButton{width: 70px;border: none;}
    </style>
</head>

<body>
    <div class="ifame-main-wrap">
        <div class="result-wrap">
            <form action="" method="post" name="mysubmitform" id="mysubmitform" enctype="multipart/form-data">
                {notempty name="info"}
                <input type="hidden" name="info[id]" value="{$info.id}">
                {/notempty}
                <input type="hidden" value="{$info.wechat_token ? $info.wechat_token : StringHelper::get_random_string(15)}" name="info[wechat_token]">
                <input type="hidden" value="{$info.wechat_encodingaeskey ? $info.wechat_encodingaeskey : StringHelper::get_random_string(43)}" name="info[wechat_encodingaeskey]">
                <div class="config-items">
                    <div class="admin-nav">
                        <div class="nav">
                            <a href="{:url('wechat_config/WechatConfig/index')}" class="hover">公众号配置</a>
                            {notempty name="info"}
                            <a href="{:url('wechat_config/WechatConfig/server_config',['id'=>$info.id])}">公众号接入</a>
                            {else/}
                            <a href="{:url('wechat_config/WechatConfig/server_config')}">公众号接入</a>
                            {/notempty}
                        </div>
                    </div>
                    <div class="result-content">
                        <table width="100%" class="insert-tab">
                            <tbody>
                                <tr class="formtr">
                                    <th class="formth" width="20%">
                                        <i class="require-red">*</i>公众号名称：
                                    </th>
                                    <td class="formtd">
                                        <input type="text" value="{$info.wechat_name|default=''}" size="32" name="info[wechat_name]" class="common-text">
                                    </td>
                                </tr>
                                <tr class="formtr">
                                    <th class="formth">
                                        <i class="require-red">*</i>公众号原始id：
                                    </th>
                                    <td class="formtd">
                                        <input type="text" value="{$info.wechat_id|default=''}" size="65" name="info[wechat_id]" class="common-text">
                                    </td>
                                </tr>
                                <tr class="formtr">
                                    <th class="formth">
                                        <i class="require-red">*</i>微信号：</th>
                                    <td class="formtd">
                                        <input type="text" value="{$info.wechat_no|default=''}" size="32" name="info[wechat_no]" class="common-text">
                                    </td>
                                </tr>
                                <tr class="formtr">
                                    <th class="formth">
                                        <i class="require-red">*</i>AppID（公众号）：</th>
                                    <td class="formtd">
                                        <input type="text" value="{$info.wechat_appid|default=''}" size="65" name="info[wechat_appid]" class="common-text">
                                    </td>
                                </tr>
                                <tr class="formtr">
                                    <th class="formth">
                                        <i class="require-red">*</i>AppSecret：
                                    </th>
                                    <td class="formtd">
                                        <input type="text" value="{$info.wechat_appsecret|default=''}" size="65" name="info[wechat_appsecret]" class="common-text">
                                    </td>
                                </tr>
                                <tr class="formtr">
                                    <th class="formth">
                                        <i class="require-red">*</i>二维码：</th>
                                    <td class="formtd">
                                        <div class="upload_div">
                                            <input type="hidden" name="info[wechat_qr]" value="{$info.wechat_qr|default=''}" id="upload_hidden_val">
                                            <span class="form_file">
                                                <div class="file_path" id="upload_pathp_picurl">
                                                    {$info.wechat_qr|default=''}
                                                </div>
                                                <!-- 上传按钮 -->
                                                <input type="button" id="uploadButton" class="uploadButton" value="本地图片">
                                                &nbsp;
                                                <!-- 加载提示 -->
                                                <span id="upload_loadingp_picurl"></span>
                                            </span>
                                            <div style="clear:both">
                                                {notempty name="info.wechat_qr"}
                                                <img src="{$info.wechat_qr}" id="img_demo" class="form_file_img_demo">
                                                {else/}
                                                <img src="{$static_path}/images/demo.png" id="img_demo" class="form_file_img_demo">
                                                {/notempty}
                                            </div>
                                        </div>
                                    </td>
                                </tr>

                                <tr class="formtr">
                                    <th class="formth">
                                        <i class="require-red">*</i>微信号类型：</th>
                                    <td class="formtd">
                                        <select name="info[wechat_type]">
                                            <option value="1" {eq name="info.wechat_type|default='0'" value="1"}selected{/eq}>订阅号</option>
                                            <option value="2" {eq name="info.wechat_type|default='0'" value="2"}selected{/eq}>服务号</option>
                                            <option value="3" {eq name="info.wechat_type|default='0'" value="3"}selected{/eq}>认证订阅号</option>
                                            <option value="4" {eq name="info.wechat_type|default='0'" value="4"}selected{/eq}>认证服务号</option>
                                        </select>
                                    </td>
                                </tr>
                                <tr class="formtr">
                                    <th class="formth">
                                        <i class="require-red">*</i>是否启用智能回复：</th>
                                    <td class="formtd">
                                    	<label>

                                            <input type="radio" class="common-radio" name="info[wechat_robot_on]" value="0" {eq name="info.wechat_robot_on|default='0'" value="0"}checked="checked"{/eq}>不启用</label>
                                        <label>
                                            <input type="radio" class="common-radio" name="info[wechat_robot_on]" value="1" {eq name="info.wechat_robot_on|default='0'" value="1"}checked="checked"{/eq}>启用</label>&nbsp;&nbsp;
                                        <font style="color:#CCCCCC; font-size:12px">启用后，用户回复时，将以智能回复模式代替自定义模式。</font>
                                    </td>
                                </tr>
                                <!-- <tr class="formtr">
                                    <th class="formth">
                                        <i class="require-red">*</i>小逗比智能回复授权码：</th>
                                    <td class="formtd">
                                        <input type="text" value="U2w9UjNwaUNEa3BObGc3UWlPOTE9eE5SandVQUFBPT0" size="65" name="info[wechat_xiaodoubi_key]" class="common-text">
                                        <br>
                                        <font style="color:#CCCCCC; font-size:12px">小逗比智能回复授权码获取地址：
                                            <a href="http://xiao.douqq.com/" target="_blank">http://xiao.douqq.com/</a></font>
                                    </td>
                                </tr> -->
                                <tr class="formtr">
                                    <th class="formth" width="20%">
                                        <i class="require-red">*</i>转在线客服</th>
                                    <td class="formtd">
                                        <input type="text" value="{$info.to_kf_keyword|default=''}" size="32" name="info[to_kf_keyword]" class="common-text">
                                        <font style="color:#CCCCCC; font-size:12px">用户发送的消息有此词时,转发至客服系统</font>
                                    </td>
                                </tr>
                                <tr class="formtr">
                                    <th class="formth"></th>
                                    <td class="formtd">
                                        <input type="button" value="提 交" class="submit-button">
                                        <input type="button" value="返 回" onClick="history.go(-1)" class="reset-button">
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </form>
        </div>
    </div>
</body>
<script src="{$static_path}/layer/layer.js" language="javascript"></script>
<link href="{$admin_assets_path}/kindeditor/themes/default/default.css" rel="stylesheet"/>
<script src="{$admin_assets_path}/kindeditor/kindeditor-min.js"></script>
<script type="text/javascript">
$(function(){
    KindEditor.ready(function(K) {
        var uploadbutton = K.uploadbutton({
            button : K('#uploadButton')[0],
            fieldName : 'imgFile',
            url : "{:url('wechat_config/WechatConfig/upload')}",
            afterUpload : function(data) {
                if (data.code == 0) {
                    $('#upload_pathp_picurl').text(data.data[0]);
                    $("#upload_hidden_val").val(data.data[0]);
                    $("#img_demo").attr('src',data.data[0]);
                    $("#upload_loadingp_picurl").remove();
                } else {
                    alert(data.msg);
                    $("#upload_loadingp_picurl").remove();
                }
            },
            afterError : function(str) {
                $("#upload_loadingp_picurl").remove();
                alert('错误信息已打印到控制台');
                console.log(str);
            }
        });
        uploadbutton.fileBox.change(function(e) {
            $("#upload_loadingp_picurl").html('<img src="{$static_path}/images/loading.gif"/>');
            uploadbutton.submit();
        });
    });
    $(".submit-button").click(function(){
        var that=$(this);
        //that.attr("disabled",true);
        $.ajax({
            type:"post",
            dataType:"json",
            url:"{:url('wechat_config/WechatConfig/save')}",
            data:$("#mysubmitform").serialize(),
            beforeSend:function(obj){
                that.val('提交中...');
            },
            complete:function(){
                that.val('提交');
            },
            success:function(data){
                if(data.code==1){
                    layer.msg(data.msg);
                    setTimeout(function(){
                        if (typeof data.url !== 'undefined') {
                            window.location = data.url;
                        }
                    },1000);
                    that.attr("disabled",false);
                }else{
                    layer.msg(data.msg);
                    setTimeout(function(){
                        that.attr("disabled",false);
                        if (data.url){window.location=data.url;}
                    },1000);
                } 
            }
        });
    });
});
</script>
</html>